public class test2 {
    public String longestPalindrome(String s) {
        if(s.length()==0 || s.length() == 1){
            return s;
        }
        int left = 0,right = 0,len = 0;
        int retleft = 0,retright = 0;
        for(int i = 1;i<s.length();i++){
            //奇数
            left = i-1; right = i+1;
            while(left>=0 && right<s.length() && s.charAt(left)==s.charAt(right)){
                left--;right++;
            }
            if(right+1-left>len){
                retleft = left;
                retright = right;
                len = right+1-left;
            }
            //偶数
            left = i-1; right = i;
            while(left>=0 && right<s.length() && s.charAt(left)==s.charAt(right)){
                left--;right++;
            }
            if(right+1-left>len){
                retleft = left;
                retright = right;
                len = right+1-left;

            }
        }

        return s.substring(retleft,retright+1);
    }
}
